package common.controls.dialog
{
	
	import kernel.application.ApplicationDisplay;
	
	import flash.events.MouseEvent;
	
	/**  
	 * 
	 * @author carrey
	 * */ 
	public class Dialog
	{
		private static var _ins:Dialog;
		private var _view:DialogView;
		private var _fun_1:Function;
		private var _fun_2:Function;
		
		public function Dialog()
		{
		}
		private function init():void
		{
			_view = new DialogView(ApplicationDisplay.stage);
			_view.btnYes.addEventListener(MouseEvent.CLICK,onYes,false,0,true);
			_view.btnNo.addEventListener(MouseEvent.CLICK, onNo, false, 0, true);
			_view.btnClose.addEventListener(MouseEvent.CLICK, onNo, false, 0, true);
		}
		public static function get instance():Dialog
		{
			if(_ins == null)
			{
				_ins = new Dialog();
			}
			return _ins;
		}
		/**
		 * 显示信息
		 * 
		 */		
		public static function showDialog(title:String="",content:String="",fun_1:Function=null,fun_2:Function=null):void
		{
			instance._view.txtTitle.text = title;
			instance._view.txtContent.text = content;
			instance._fun_1 = fun_1;
			instance._fun_2 = fun_2;
			instance._view.show();
		}
		/**
		 * 显示html信息
		 * 
		 */		
		public static function showHtmlDialog(title:String="",content:String="",fun_1:Function=null,fun_2:Function=null):void
		{
			instance._view.txtTitle.text = title;
			instance._view.txtContent.htmlText = content;
			instance._fun_1 = fun_1;
			instance._fun_2 = fun_2;
			instance._view.show();
		}
		public static function destroy():void
		{
			if(_ins)
			{
				_ins.destroy();
				_ins=null;
			}
		}
		public function destroy():void
		{
			_view.btnYes.removeEventListener(MouseEvent.CLICK,onYes);
			_view.btnNo.removeEventListener(MouseEvent.CLICK, onNo);
			_view.btnClose.removeEventListener(MouseEvent.CLICK, onNo);
		}
		/**
		 *确定 
		 * @param evt
		 * 
		 */		
		private function onYes(evt:MouseEvent):void
		{
			if(_fun_1 != null)
			{
				_fun_1();
			}
			_fun_1=null;
			_fun_2=null;
			_view.close();
		}
		/**
		 *取消 
		 * @param evt
		 * 
		 */		
		private function onNo(evt:MouseEvent):void
		{
			if(_fun_2 != null)
			{
				_fun_2();
			}
			_fun_1=null;
			_fun_2=null;
			_view.close();
		}
	}
}